package cn.easybuy.service.product;

import java.sql.Connection;
import java.util.List;

import org.junit.Test;

import cn.easybuy.dao.ProductDao;
import cn.easybuy.dao.impl.ProductDaoImpl;
import cn.easybuy.entity.Product;
import cn.easybuy.utils.DataSourceUtil;

public class ProductServiceImpl implements ProductService {

	@Override
	public List<Product> findProduct() {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.findProduct();
	}

	//测试遍历商品集合
	@Test
	public void Test(){
		ProductService ps=new ProductServiceImpl();
		List<Product> list=ps.findProduct();
		for(Product p : list){
			System.out.println(p.getName()+p.getCategoryLevel1Id());
		}
	}
	@Override
	public List<Product> findProductByLevel1(String categoryLevel1) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.findProductByLevel1(categoryLevel1);
	}

	@Override
	public Product findProductById(String id) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.findProductById(id);
	}

	@Override
	public int findStockById(String id) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.findStockById(id);
	}

	@Override
	public List<Product> searchProduct(String name) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.searchProduct(name);
	}

	@Override
	public int addProduct(Product product) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.addProduct(product);
	}

	@Override
	public int delProduct(String ProductId) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.delProduct(ProductId);
	}

	@Override
	public int updateProduct(Product product) {
		// TODO Auto-generated method stub
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.updateProduct(product);
	}

	@Override
	public int subtractStock(String id, int num) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.subtractStock(id, num);
	}

	@Override
	public List<Product> getPageList(int pageNo, int pageSize) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.getPageList(pageNo, pageSize);
	}

	@Override
	public int getCount() {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.getCount();
	}

	@Override
	public int findProductToCategoryId(String categoryId) {
		ProductDao productDao=new ProductDaoImpl(DataSourceUtil.getConnection());
		return productDao.findProductToCategoryId(categoryId);
	}

}
